/*
 * @Descripttion: 应用程序请求中间件，在每次请求时触发。可在配置文件中设置是否启用
 * @version: 
 * @Author: turingchang
 * @Date: 2020-08-23 08:59:54
 * @LastEditors: turingchang
 * @LastEditTime: 2020-09-08 14:52:10
 */

let ms = require('m-service');

module.exports = (options, app) => {
    return async function xsoaHandler(ctx, next) {
        if (options.enable && options.enable === true) {
            ms.createApp({
                centers: options.center, //指定注册服务中心      
                services: { //启动服务
                    port: app.config.cluster.listen.port,
                    dir: __dirname,
                    names: [options.localServerName],
                }
            });
            await next(options);
        } else {
            await next(options);
        }
    };

};